package com.cap.dreamcircle.View;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cap.dreamcircle.App.App;
import com.cap.dreamcircle.Base.BaseActivity;
import com.cap.dreamcircle.Model.Bean.BaseBean;
import com.cap.dreamcircle.Model.Bean.UnReadMsgBean;
import com.cap.dreamcircle.Model.IMessageModel;
import com.cap.dreamcircle.Model.Impl.MessageModelImpl;
import com.cap.dreamcircle.R;
import com.cap.dreamcircle.Utils.CommonSubscriber;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.functions.Action0;

/**
 * Created by liucxu on 2018/3/22.
 */

public class MessageCenterActivity extends BaseActivity {
    @BindView(R.id.imv_back)
    ImageView imv_back;
    @BindView(R.id.layout_notify)
    RelativeLayout layout_notify;
    @BindView(R.id.layout_system)
    RelativeLayout layout_system;
    @BindView(R.id.imv_notify)
    ImageView imv_notify;
    @BindView(R.id.imv_system)
    ImageView imv_system;

    private IMessageModel model;


    @Override
    public int getLayoutId() {
        return R.layout.activity_message_center;
    }

    @Override
    public void setupView() {
        ButterKnife.bind(this);
        imv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                App.GetInstance().finishActivity(MessageCenterActivity.this);
            }
        });
        layout_notify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MessageCenterActivity.this, NotifyActivity.class);
                startActivity(intent);
            }
        });
        layout_system.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MessageCenterActivity.this, SystemMessagesActivity.class);
                startActivity(intent);
            }
        });
        model = new MessageModelImpl();
    }

    @Override
    protected void onResume() {
        super.onResume();
        RequestMessageCount();
    }

    private void RequestMessageCount() {
        model.RequestMessageCount().doOnSubscribe(new Action0() {
            @Override
            public void call() {
                showProgress();
            }
        }).subscribe(new CommonSubscriber<UnReadMsgBean>() {
            @Override
            public void onSuccess(UnReadMsgBean response) {
                hideProgress();
                if(response.getMsgCount()>0){
                    imv_notify.setVisibility(View.VISIBLE);
                }
                else{
                    imv_notify.setVisibility(View.GONE);
                }

                if(response.getSysMsgCount()>0){
                    imv_system.setVisibility(View.VISIBLE);
                }
                else{
                    imv_system.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailure(BaseBean response) {
                hideProgress();
            }
        });
    }

    @Override
    public void setupData() {

    }
}
